import request from '@/utils/request'
import type { AllPermissonListResponseData, PermissionData } from './type'

const API = {
  ALLPERMISSIONLIST_URL: '/admin/acl/permission',
  ADDPERMISSION_URL: '/admin/acl/permission/save',
  UPDATEPERMISSION_URL: '/admin/acl/permission/update',
  DELETEPERMISSION_URL: '/admin/acl/permission/remove/',
}

export const reqAllPermissionList = async () =>
  await request.get<any, AllPermissonListResponseData>(
    API.ALLPERMISSIONLIST_URL,
  )

export const reqAddOrUpdatePermission = async (data: PermissionData) => {
  if (data.id) {
    return await request.put<any, any>(API.UPDATEPERMISSION_URL, data)
  } else {
    return await request.post<any, any>(API.ADDPERMISSION_URL, data)
  }
}

export const reqDeletePermission = async (permissionId: number) =>
  await request.delete<any, any>(API.DELETEPERMISSION_URL + permissionId)
